axios.defaults.baseURL = "http://localhost:8080"; // 给Axios设置统一的请求前缀
// 给Vue设置一个属性
Vue.prototype.$http = axios
function urlgetobj(url) {
    let paramObj = {};
    if(url.indexOf("?") > 0){
        url = url.substring(url.indexOf("?")+1) // typeId=27&xxx=yyyy
        let paramArray = url.split("&")
        for(var i=0;i<paramArray.length;i++){   // typeId=27
            let key = paramArray[i].split("=")[0]   // typeId
            let value = paramArray[i].split("=")[1]
            paramObj[key] = value;
        }
    }
    return paramObj;

}
var url = location.href;

var releasePath = ["index.html","about.html","callback.html","binder.html","exam.html"];

url = url.substring(url.lastIndexOf("/")+1);
var isRun = false;
if(!url){
    isRun = true;
}else{
    for(var i=0;i<releasePath.length;i++){
        var path = releasePath[i];
        if(url.indexOf(path) > -1){
            isRun = true;
            break;
        }
    }
}
if(!isRun){
    var loginUser = JSON.parse(localStorage.getItem("loginUser"));
    if(!loginUser){
        alert("当前操作需要登录后才能访问,请登陆后重试!");
        location.href = "/index.html";
    }
}

axios.interceptors.request.use(
    config => {

        let token = localStorage.getItem("token");

        if (token) {
            config.headers["token"] = token;
        }
        return config
    },
    error => {
        return Promise.reject(error)
    })

axios.interceptors.response.use(function(response){

    let result = response.data;
    if(!result.success && result.message == "noLogin"){
        alert("当前资源需要登陆后才能访问!")
    }
    return response
},function(err){
    return Promise.reject(err)
})
